package com.aj.activity.fragment;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.widget.Toast;

import com.aj.activity.HomeActivity;
import com.aj.activity.R;
import com.aj.activity.adapter.InfoPagerAdapter;
import com.aj.activity.adapter.TaskInfoAdapter;
import com.aj.activity.adapter.TaskInfoAdapter.IButtonClick;
import com.aj.activity.dialog.ProgressDialog;
import com.aj.application.LoveHomeApplication;
import com.aj.databases.dao.UserDao;
import com.aj.databases.entry.TaskInfo;
import com.aj.databases.entry.User;
import com.aj.http.AsynchronizationHttpRequest.IHttpCallBack;
import com.aj.http.request.AcceptTaskRequest;
import com.aj.http.request.CannelTaskRequest;
import com.aj.http.request.QueryTaskListRequest;
import com.aj.http.response.BaseRespond;
import com.aj.http.response.Common;
import com.aj.http.response.QueryTaskListResponse;

/**
 * A simple {@link Fragment} subclass.
 */
public class TaskFragment extends Fragment implements OnCheckedChangeListener,
		IButtonClick {
	private static final String TAG = TaskFragment.class.getName();
	private ImageView cursor;
	private RadioGroup mRadioGroup;
	private RadioButton mRadioButton1;
	private RadioButton mRadioButton2;
	private RadioButton mRadioButton3;
	private RadioButton mRadioButton4;
	private RadioButton mRadioButton5;
	private ListView todayListView;
	private TaskInfoAdapter todayAdapter;
	private List<TaskInfo> todayTaskInfoList = new ArrayList<TaskInfo>();
	private ListView tomorrowListView;
	private TaskInfoAdapter tomorrowAdapter;
	private List<TaskInfo> tomorrowTaskInfoList = new ArrayList<TaskInfo>();
	private ListView distantListView;
	private TaskInfoAdapter distantAdapter;
	private List<TaskInfo> distantTaskInfoList = new ArrayList<TaskInfo>();
	private ListView historyListView;
	private TaskInfoAdapter historyAdapter;
	private List<TaskInfo> historyTaskInfoList = new ArrayList<TaskInfo>();
	private ListView mySendListView;
	private TaskInfoAdapter mySendAdapter;
	private List<TaskInfo> mySendTaskInfoList = new ArrayList<TaskInfo>();
	private ViewPager viewPager;
	// private RadioButton mRadioButton7;
	private HorizontalScrollView mHorizontalScrollView;
	private List<View> pagerViews = new ArrayList<View>(); // 滑动的布局集合
	private int itemPosition = 0;
	protected ProgressDialog progressDialog;

	protected void showProgressDialog() {
		if (progressDialog == null) {
			progressDialog = new ProgressDialog(getActivity());
		}
		progressDialog.show();
	}

	protected void showProgressDialog(String text) {
		if (progressDialog == null) {
			progressDialog = new ProgressDialog(getActivity());
		}
		progressDialog.show();
		progressDialog.setContentText(text);
	}

	protected void showProgressDialog(int textID) {
		if (progressDialog == null) {
			progressDialog = new ProgressDialog(getActivity());
		}
		progressDialog.show();
		progressDialog.setContentText(textID);
	}

	protected void dimissProgressDialog() {
		if (progressDialog != null && progressDialog.isShowing()) {
			progressDialog.dismiss();
			progressDialog = null;
		}
	}

	private float mCurrentCheckedRadioLeft;

	private View bodyView;
	private User user;
	private UserDao userDao;

	public TaskFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		userDao = new UserDao(getActivity());
		user = userDao.getCurrentUser(LoveHomeApplication.token);
		bodyView = inflater.inflate(R.layout.fragment_task, container, false);
		initCursor();
		initPager();
		createMenu();
		mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();
		return bodyView;
	}

	private float getCurrentCheckedRadioLeft() {
		if (mRadioButton1.isChecked()) {
			return getResources().getDimension(R.dimen.rdo1);
		} else if (mRadioButton2.isChecked()) {
			return getResources().getDimension(R.dimen.rdo2);
		} else if (mRadioButton3.isChecked()) {
			return getResources().getDimension(R.dimen.rdo3);
		} else if (mRadioButton4.isChecked()) {
			return getResources().getDimension(R.dimen.rdo4);
		} else if (mRadioButton5.isChecked()) {
			return getResources().getDimension(R.dimen.rdo5);
		}
		return 0f;
	}

	private void initCursor() {
		mRadioGroup = (RadioGroup) bodyView.findViewById(R.id.radioGroup);
		mRadioButton1 = (RadioButton) bodyView.findViewById(R.id.btn1);
		mRadioButton2 = (RadioButton) bodyView.findViewById(R.id.btn2);
		mRadioButton3 = (RadioButton) bodyView.findViewById(R.id.btn3);
		mRadioButton4 = (RadioButton) bodyView.findViewById(R.id.btn4);
		mRadioButton5 = (RadioButton) bodyView.findViewById(R.id.btn5);
		cursor = (ImageView) bodyView.findViewById(R.id.cursor);
		mHorizontalScrollView = (HorizontalScrollView) bodyView
				.findViewById(R.id.horizontalScrollView);
	}

	private void initPager() {
		viewPager = (ViewPager) bodyView.findViewById(R.id.view_pager);
		pagerViews.clear();
		viewPager.removeAllViews();
		pagerViews.add(getTodayTask());
		pagerViews.add(getTomorrowTask());
		pagerViews.add(getDistantTask());
		pagerViews.add(getHistoryTask());
		pagerViews.add(getMySendTask());
		viewPager.setAdapter(new InfoPagerAdapter(pagerViews));
		viewPager.setOnPageChangeListener(new PagerOnPageChangeListener());
		mRadioGroup.setOnCheckedChangeListener(this);
		viewPager.setCurrentItem(itemPosition);
	}

	@Override
	public void onResume() {
		super.onResume();
		if (user == null) {
			return;
		}
		refershMySendTask();
		refreshHistoryTask();
		refreshDistantTask();
		refreshTomorrowTask();
		refreshTodayTask();
	}

	public void refershMySendTask() {
		new QueryTaskListRequest().excute(getActivity(), user.getUser_id(),
				"0", "0", "50", new IHttpCallBack() {
					@Override
					public void success(String result) {
						try {
							QueryTaskListResponse queryTaskListResponse = new QueryTaskListResponse(
									new JSONObject(result));
							mySendTaskInfoList = queryTaskListResponse
									.getTaskInfoList();
							if (mySendTaskInfoList != null) {
								mySendAdapter = new TaskInfoAdapter(
										getActivity(), mySendTaskInfoList, true);
								mySendAdapter.setButtonClick(TaskFragment.this);
								mySendListView.setAdapter(mySendAdapter);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void fail(String result) {
						Log.e(TAG, "QueryTaskListRequest error result:"
								+ result);
					}
				});
	}

	private View getMySendTask() {
		mySendListView = new ListView(getActivity());
		return mySendListView;
	}

	private void refreshHistoryTask() {
		new QueryTaskListRequest().excute(getActivity(), user.getUser_id(),
				"4", "0", "50", new IHttpCallBack() {
					@Override
					public void success(String result) {
						try {
							QueryTaskListResponse queryTaskListResponse = new QueryTaskListResponse(
									new JSONObject(result));
							historyTaskInfoList = queryTaskListResponse
									.getTaskInfoList();
							if (historyTaskInfoList != null) {
								historyAdapter = new TaskInfoAdapter(
										getActivity(), historyTaskInfoList,
										false);
								historyAdapter
										.setButtonClick(TaskFragment.this);
								historyListView.setAdapter(historyAdapter);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void fail(String result) {
						Log.e(TAG, "QueryTaskListRequest error result:"
								+ result);
					}
				});
	}

	private View getHistoryTask() {
		historyListView = new ListView(getActivity());
		return historyListView;
	}

	private void refreshDistantTask() {
		new QueryTaskListRequest().excute(getActivity(), user.getUser_id(),
				"3", "0", "50", new IHttpCallBack() {
					@Override
					public void success(String result) {
						try {
							QueryTaskListResponse queryTaskListResponse = new QueryTaskListResponse(
									new JSONObject(result));
							distantTaskInfoList = queryTaskListResponse
									.getTaskInfoList();
							if (distantTaskInfoList != null) {
								distantAdapter = new TaskInfoAdapter(
										getActivity(), distantTaskInfoList,
										false);
								distantAdapter
										.setButtonClick(TaskFragment.this);
								distantListView.setAdapter(distantAdapter);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void fail(String result) {
						Log.e(TAG, "QueryTaskListRequest error result:"
								+ result);
					}
				});
	}

	private View getDistantTask() {
		distantListView = new ListView(getActivity());
		return distantListView;
	}

	private void refreshTomorrowTask() {
		new QueryTaskListRequest().excute(getActivity(), user.getUser_id(),
				"2", "0", "50", new IHttpCallBack() {
					@Override
					public void success(String result) {
						try {
							QueryTaskListResponse queryTaskListResponse = new QueryTaskListResponse(
									new JSONObject(result));
							tomorrowTaskInfoList = queryTaskListResponse
									.getTaskInfoList();
							if (tomorrowTaskInfoList != null) {
								tomorrowAdapter = new TaskInfoAdapter(
										getActivity(), tomorrowTaskInfoList,
										false);
								tomorrowAdapter
										.setButtonClick(TaskFragment.this);
								tomorrowListView.setAdapter(tomorrowAdapter);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void fail(String result) {
						Log.e(TAG, "QueryTaskListRequest error result:"
								+ result);
					}
				});
	}

	private View getTomorrowTask() {
		tomorrowListView = new ListView(getActivity());
		return tomorrowListView;
	}

	private void refreshTodayTask() {
		new QueryTaskListRequest().excute(getActivity(), user.getUser_id(),
				"1", "0", "50", new IHttpCallBack() {
					@Override
					public void success(String result) {
						try {
							QueryTaskListResponse queryTaskListResponse = new QueryTaskListResponse(
									new JSONObject(result));
							todayTaskInfoList = queryTaskListResponse
									.getTaskInfoList();
							if (todayTaskInfoList != null) {
								todayAdapter = new TaskInfoAdapter(
										getActivity(), todayTaskInfoList, false);
								todayAdapter.setButtonClick(TaskFragment.this);
								todayListView.setAdapter(todayAdapter);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void fail(String result) {
						Log.e(TAG, "QueryTaskListRequest error result:"
								+ result);
					}
				});
	}

	private View getTodayTask() {
		todayListView = new ListView(getActivity());
		return todayListView;
	}

	/**
	 * 页卡切换监听
	 */
	public class PagerOnPageChangeListener implements OnPageChangeListener {
		@Override
		public void onPageSelected(int position) {

			if (position == 0) {
				mRadioButton1.performClick();
			} else if (position == 1) {
				mRadioButton2.performClick();
			} else if (position == 2) {
				mRadioButton3.performClick();
			} else if (position == 3) {
				mRadioButton4.performClick();
			} else if (position == 4) {
				mRadioButton5.performClick();
			}
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
		}

		@Override
		public void onPageScrollStateChanged(int arg0) {
		}
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {

		AnimationSet _AnimationSet = new AnimationSet(true);
		TranslateAnimation _TranslateAnimation;

		if (checkedId == R.id.btn1) {
			itemPosition = 0;
			_TranslateAnimation = new TranslateAnimation(
					mCurrentCheckedRadioLeft, getResources().getDimension(
							R.dimen.rdo1), 0f, 0f);
			_AnimationSet.addAnimation(_TranslateAnimation);
			_AnimationSet.setFillBefore(false);
			_AnimationSet.setFillAfter(true);
			_AnimationSet.setDuration(100);
			/*
			 * LayoutParams _LayoutParams1 = new LayoutParams(100, 4);
			 * _LayoutParams1.setMargins(0, 0, 0, 0);
			 * _LayoutParams1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
			 */
			// mImageView.bringToFront();
			cursor.startAnimation(_AnimationSet);// ��ʼ������ɫ����ͼƬ�Ķ����л�
			// mImageView.setLayoutParams(_LayoutParams1);
			viewPager.setCurrentItem(0);
		} else if (checkedId == R.id.btn2) {
			itemPosition = 1;
			_TranslateAnimation = new TranslateAnimation(
					mCurrentCheckedRadioLeft, getResources().getDimension(
							R.dimen.rdo2), 0f, 0f);

			_AnimationSet.addAnimation(_TranslateAnimation);
			_AnimationSet.setFillBefore(false);
			_AnimationSet.setFillAfter(true);
			_AnimationSet.setDuration(100);

			// mImageView.bringToFront();
			cursor.startAnimation(_AnimationSet);

			viewPager.setCurrentItem(1);
		} else if (checkedId == R.id.btn3) {
			itemPosition = 2;
			_TranslateAnimation = new TranslateAnimation(
					mCurrentCheckedRadioLeft, getResources().getDimension(
							R.dimen.rdo3), 0f, 0f);

			_AnimationSet.addAnimation(_TranslateAnimation);
			_AnimationSet.setFillBefore(false);
			_AnimationSet.setFillAfter(true);
			_AnimationSet.setDuration(100);

			// mImageView.bringToFront();
			cursor.startAnimation(_AnimationSet);

			viewPager.setCurrentItem(2);
		} else if (checkedId == R.id.btn4) {
			itemPosition = 3;
			_TranslateAnimation = new TranslateAnimation(
					mCurrentCheckedRadioLeft, getResources().getDimension(
							R.dimen.rdo4), 0f, 0f);

			_AnimationSet.addAnimation(_TranslateAnimation);
			_AnimationSet.setFillBefore(false);
			_AnimationSet.setFillAfter(true);
			_AnimationSet.setDuration(100);

			// mImageView.bringToFront();
			cursor.startAnimation(_AnimationSet);
			viewPager.setCurrentItem(3);
		} else if (checkedId == R.id.btn5) {
			itemPosition = 4;
			_TranslateAnimation = new TranslateAnimation(
					mCurrentCheckedRadioLeft, getResources().getDimension(
							R.dimen.rdo5), 0f, 0f);

			_AnimationSet.addAnimation(_TranslateAnimation);
			_AnimationSet.setFillBefore(false);
			_AnimationSet.setFillAfter(true);
			_AnimationSet.setDuration(100);

			// mImageView.bringToFront();
			cursor.startAnimation(_AnimationSet);

			viewPager.setCurrentItem(4);
		}
		mCurrentCheckedRadioLeft = getCurrentCheckedRadioLeft();
		mHorizontalScrollView.smoothScrollTo((int) mCurrentCheckedRadioLeft
				- (int) getResources().getDimension(R.dimen.rdo2), 0);

	}

	@Override
	public void acceptTask(TaskInfo taskInfo) {
		showProgressDialog();
		new AcceptTaskRequest().excute(getActivity(), taskInfo.getId(), "0",
				user.getUser_id(), "2", new IHttpCallBack() {
					@Override
					public void success(String result) {
						try {
							dimissProgressDialog();
							Common common = new Common(new JSONObject(result));
							Toast.makeText(getActivity(), common.getErrorMsg(),
									Toast.LENGTH_LONG).show();
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void fail(String result) {
						try {
							dimissProgressDialog();
							Common common = new Common(new JSONObject(result));
							Toast.makeText(getActivity(), common.getErrorMsg(),
									Toast.LENGTH_LONG).show();
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
				});
	}

	@Override
	public void refuseTask(TaskInfo taskInfo) {
		showProgressDialog();
		new AcceptTaskRequest().excute(getActivity(), taskInfo.getId(), "0",
				user.getUser_id(), "0", new IHttpCallBack() {
					@Override
					public void success(String result) {
						try {
							dimissProgressDialog();
							Common common = new Common(new JSONObject(result));
							Toast.makeText(getActivity(), common.getErrorMsg(),
									Toast.LENGTH_LONG).show();
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void fail(String result) {
						try {
							dimissProgressDialog();
							Common common = new Common(new JSONObject(result));
							Toast.makeText(getActivity(), common.getErrorMsg(),
									Toast.LENGTH_LONG).show();
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
				});
	}

	@Override
	public void cannelTask(final TaskInfo taskInfo) {
		showProgressDialog();
		new CannelTaskRequest().excute(getActivity(), taskInfo.getId(), "0",
				user.getUser_id(), new IHttpCallBack() {
					@Override
					public void success(String result) {
						try {
							dimissProgressDialog();
							Common common = new Common(new JSONObject(result));
							if (common.getReturnCode() != null
									&& common
											.getReturnCode()
											.trim()
											.equals(BaseRespond.SUCCESS_RESULT_CODE_STRING)) {
								mySendTaskInfoList.remove(taskInfo);
								mySendAdapter.notifyDataSetChanged();
							}
							Toast.makeText(getActivity(), common.getErrorMsg(),
									Toast.LENGTH_LONG).show();
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void fail(String result) {
						try {
							dimissProgressDialog();
							Common common = new Common(new JSONObject(result));
							Toast.makeText(getActivity(), common.getErrorMsg(),
									Toast.LENGTH_LONG).show();
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}
				});
	}

	private TextView accept_text;
	private TextView accept_all_text;
	private TextView refuse_text;
	private TextView refuse_all_text;
	private TextView create_text;
	private Button cannel_or_cannelbutton;

	private void createMenu() {
		View view = LayoutInflater.from(getActivity()).inflate(
				R.layout.menu_task_edit, null);
		accept_text = (TextView) view.findViewById(R.id.accept_text);
		accept_all_text = (TextView) view.findViewById(R.id.accept_all_text);
		refuse_text = (TextView) view.findViewById(R.id.refuse_text);
		refuse_all_text = (TextView) view.findViewById(R.id.refuse_all_text);
		create_text = (TextView) view.findViewById(R.id.create_text);
		cannel_or_cannelbutton = (Button) view
				.findViewById(R.id.cannel_or_cannelbutton);
		MenuClickEvent menuClickEvent = new MenuClickEvent();
		accept_text.setOnClickListener(menuClickEvent);
		accept_all_text.setOnClickListener(menuClickEvent);
		refuse_text.setOnClickListener(menuClickEvent);
		refuse_all_text.setOnClickListener(menuClickEvent);
		create_text.setOnClickListener(menuClickEvent);
		cannel_or_cannelbutton.setOnClickListener(menuClickEvent);
		((HomeActivity) getActivity()).setMenuLayout(view);
	}

	class MenuClickEvent implements OnClickListener {
		@Override
		public void onClick(View v) {
			((HomeActivity) getActivity()).closePanel();
			List<TaskInfo> taskInfoList = new ArrayList<TaskInfo>();
			if (viewPager.getCurrentItem() == 0) {
				taskInfoList = todayAdapter.getChooseTaskInfoList();
			} else if (viewPager.getCurrentItem() == 1) {
				taskInfoList = tomorrowAdapter.getChooseTaskInfoList();
			} else if (viewPager.getCurrentItem() == 2) {
				taskInfoList = distantAdapter.getChooseTaskInfoList();
			} else if (viewPager.getCurrentItem() == 3) {
				taskInfoList = historyAdapter.getChooseTaskInfoList();
			}
			String taskIds = "";
			switch (v.getId()) {
			case R.id.accept_text:
				if (taskInfoList == null || taskInfoList.size() == 0) {
					Toast.makeText(getActivity(), "没有选中任务，请重新操作~",
							Toast.LENGTH_LONG).show();
					return;
				}
				taskIds = "";
				for (TaskInfo taskInfo : taskInfoList) {
					taskIds += taskInfo.getId() + ",";
				}
				taskIds = taskIds.substring(0, taskIds.lastIndexOf(","));
				showProgressDialog();
				new AcceptTaskRequest().excute(getActivity(), taskIds, "0",
						user.getUser_id(), "2", new IHttpCallBack() {

							@Override
							public void success(String result) {
								try {
									dimissProgressDialog();
									Common common = new Common(new JSONObject(
											result));
									Toast.makeText(getActivity(),
											common.getErrorMsg(),
											Toast.LENGTH_LONG).show();
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}

							@Override
							public void fail(String result) {
								try {
									dimissProgressDialog();
									Common common = new Common(new JSONObject(
											result));
									Toast.makeText(getActivity(),
											common.getErrorMsg(),
											Toast.LENGTH_LONG).show();
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}
						});
				break;
			case R.id.accept_all_text:
				if (taskInfoList == null || taskInfoList.size() == 0) {
					Toast.makeText(getActivity(), "没有选中任务，请重新操作~",
							Toast.LENGTH_LONG).show();
					return;
				}
				taskIds = "";
				for (TaskInfo taskInfo : taskInfoList) {
					taskIds += taskInfo.getId() + ",";
				}
				taskIds = taskIds.substring(0, taskIds.lastIndexOf(","));
				showProgressDialog();
				new AcceptTaskRequest().excute(getActivity(), taskIds, "1",
						user.getUser_id(), "2", new IHttpCallBack() {

							@Override
							public void success(String result) {
								try {
									dimissProgressDialog();
									Common common = new Common(new JSONObject(
											result));
									Toast.makeText(getActivity(),
											common.getErrorMsg(),
											Toast.LENGTH_LONG).show();
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}

							@Override
							public void fail(String result) {
								try {
									dimissProgressDialog();
									Common common = new Common(new JSONObject(
											result));
									Toast.makeText(getActivity(),
											common.getErrorMsg(),
											Toast.LENGTH_LONG).show();
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}
						});
				break;
			case R.id.refuse_text:
				if (taskInfoList == null || taskInfoList.size() == 0) {
					Toast.makeText(getActivity(), "没有选中任务，请重新操作~",
							Toast.LENGTH_LONG).show();
					return;
				}
				taskIds = "";
				for (TaskInfo taskInfo : taskInfoList) {
					taskIds += taskInfo.getId() + ",";
				}
				taskIds = taskIds.substring(0, taskIds.lastIndexOf(","));
				showProgressDialog();
				new AcceptTaskRequest().excute(getActivity(), taskIds, "0",
						user.getUser_id(), "0", new IHttpCallBack() {

							@Override
							public void success(String result) {
								try {
									dimissProgressDialog();
									Common common = new Common(new JSONObject(
											result));
									Toast.makeText(getActivity(),
											common.getErrorMsg(),
											Toast.LENGTH_LONG).show();
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}

							@Override
							public void fail(String result) {
								try {
									dimissProgressDialog();
									Common common = new Common(new JSONObject(
											result));
									Toast.makeText(getActivity(),
											common.getErrorMsg(),
											Toast.LENGTH_LONG).show();
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}
						});
				break;
			case R.id.refuse_all_text:
				if (taskInfoList == null || taskInfoList.size() == 0) {
					Toast.makeText(getActivity(), "没有选中任务，请重新操作~",
							Toast.LENGTH_LONG).show();
					return;
				}
				taskIds = "";
				for (TaskInfo taskInfo : taskInfoList) {
					taskIds += taskInfo.getId() + ",";
				}
				taskIds = taskIds.substring(0, taskIds.lastIndexOf(","));
				showProgressDialog();
				new AcceptTaskRequest().excute(getActivity(), taskIds, "1",
						user.getUser_id(), "0", new IHttpCallBack() {

							@Override
							public void success(String result) {
								try {
									dimissProgressDialog();
									Common common = new Common(new JSONObject(
											result));
									Toast.makeText(getActivity(),
											common.getErrorMsg(),
											Toast.LENGTH_LONG).show();
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}

							@Override
							public void fail(String result) {
								try {
									dimissProgressDialog();
									Common common = new Common(new JSONObject(
											result));
									Toast.makeText(getActivity(),
											common.getErrorMsg(),
											Toast.LENGTH_LONG).show();
								} catch (JSONException e) {
									e.printStackTrace();
								}
							}
						});
				break;
			case R.id.create_text:
				Intent intent = new Intent("com.aj.activity.CreateTaskActvity");
				startActivity(intent);
				break;
			case R.id.cannel_or_cannelbutton:
				break;
			}
		}
	}
}
